﻿using Hicap.AuthorizationServer.Core.Models;
using Microsoft.EntityFrameworkCore;

namespace Hicap.AuthorizationServer.Core.Common.EFCore
{
    public class AuthorizationDbContext : DbContext
    {
        public DbSet<AuthObject> AuthObject { get; set; }
        public DbSet<AuthObjectRoleRelated> AuthObjectRoleRelated { get; set; }
        public DbSet<Company> Company { get; set; }

        public DbSet<Notification> Notification { get; set; }
        public DbSet<Role> Role { get; set; }
        public DbSet<User> User { get; set; }
        public DbSet<UserLoginAttempt> UserLoginAttempt { get; set; }

        public DbSet<UserRoleRelated> UserRoleRelated { get; set; }

        public AuthorizationDbContext(DbContextOptions options)
            : base(options)
        {
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<User>().HasIndex(x => x.UserCode).IsUnique();

            // enable auto history functionality.
            modelBuilder.EnableAutoHistory(null);
            base.OnModelCreating(modelBuilder);
        }
    }
}